package sorting

import "gitee.com/guuzaa/sorting/constraints"

func CombSort[T constraints.Ordered](arr []T) []T {
	if len(arr) < 2 {
		return arr
	}

	var i int
	gap := len(arr)

	for gap > 0 {
		gap = int(float32(gap) * 0.8)
		i = gap
		for i < len(arr) {
			if arr[i-gap] > arr[i] {
				arr[i-gap], arr[i] = arr[i], arr[i-gap]
			}
			i++
		}
	}

	return BubbleSort(arr)
}
